<template>
  <div class="banner" :style="{
    backgroundColor: config.pageConfig.color,
  }">
    <div :style="{
      marginTop: config.pageConfig.marginTop + 'px',
      marginBottom: config.pageConfig.marginBottom + 'px',
      marginLeft: config.pageConfig.margin + 'px',
      marginRight: config.pageConfig.margin + 'px',
    }">
      <div class="img">
        <div v-if="config.pageConfig.custom == '1'" class="banner-container style-1">
          <div class="img-container" :class="config.pageConfig.style == 2 ? 'shadow-style' : ''" :style="
            config.pageConfig.style == 3
              ? {
                borderColor: config.pageConfig.borderColor,
                borderWidth: config.pageConfig.borderWidth + 'px',
              }
              : ''
          ">
            <img v-if="config.pageConfig.imgList[0].imgUrl" :src="config.pageConfig.imgList[0].imgUrl"
              class="banner-img" :style="{
                borderTopLeftRadius: config.pageConfig.radiusTop + 'px',
                borderTopRightRadius: config.pageConfig.radiusTop + 'px',
                borderBottomLeftRadius: config.pageConfig.radiusBottom + 'px',
                borderBottomRightRadius: config.pageConfig.radiusBottom + 'px',
              }" alt="" />
            <img v-else :style="{
              borderTopLeftRadius: config.pageConfig.radiusTop + 'px',
              borderTopRightRadius: config.pageConfig.radiusTop + 'px',
              borderBottomLeftRadius: config.pageConfig.radiusBottom + 'px',
              borderBottomRightRadius: config.pageConfig.radiusBottom + 'px',
            }" src="../../../../../../assets/app/bar/default_banner.png" class="banner-img" alt="" />
          </div>
        </div>

        <div v-if="config.pageConfig.custom == '2'" class="banner-container style-2">
          <div class="img-container" :class="config.pageConfig.style == 2 ? 'shadow-style' : ''" :style="{
            borderTopLeftRadius: config.pageConfig.radiusTop + 'px',
            borderTopRightRadius: config.pageConfig.radiusTop + 'px',
            borderBottomLeftRadius: config.pageConfig.radiusBottom + 'px',
            borderBottomRightRadius: config.pageConfig.radiusBottom + 'px',
            borderWidth:
              config.pageConfig.style == 3
                ? config.pageConfig.borderWidth + 'px'
                : '',
            borderColor:
              config.pageConfig.style == 3
                ? config.pageConfig.borderColor
                : '',
          }" v-if="config.pageConfig.imgList.length > 0">
            <img :style="{
              borderTopLeftRadius: config.pageConfig.radiusTop + 'px',
              borderTopRightRadius: config.pageConfig.radiusTop + 'px',
              borderBottomLeftRadius: config.pageConfig.radiusBottom + 'px',
              borderBottomRightRadius: config.pageConfig.radiusBottom + 'px',
            }" v-if="config.pageConfig.imgList[0].imgUrl" :src="config.pageConfig.imgList[0].imgUrl"
              class="banner-img" alt="" />
            <img v-else :style="{
              borderTopLeftRadius: config.pageConfig.radiusTop + 'px',
              borderTopRightRadius: config.pageConfig.radiusTop + 'px',
              borderBottomLeftRadius: config.pageConfig.radiusBottom + 'px',
              borderBottomRightRadius: config.pageConfig.radiusBottom + 'px',
            }" src="../../../../../../assets/app/bar/default_banner.png" class="banner-img" alt="" />
          </div>
          <div class="img-container" :class="config.pageConfig.style == 2 ? 'shadow-style' : ''" :style="{
            marginLeft: config.pageConfig.marginImg + 'px',
            marginRight: config.pageConfig.marginImg + 'px',
            borderTopLeftRadius: config.pageConfig.radiusTop + 'px',
            borderTopRightRadius: config.pageConfig.radiusTop + 'px',
            borderBottomLeftRadius: config.pageConfig.radiusBottom + 'px',
            borderBottomRightRadius: config.pageConfig.radiusBottom + 'px',
            borderWidth:
              config.pageConfig.style == 3
                ? config.pageConfig.borderWidth + 'px'
                : '',
            borderColor:
              config.pageConfig.style == 3
                ? config.pageConfig.borderColor
                : '',
          }" v-if="config.pageConfig.imgList.length > 1">
            <img :style="{
              borderTopLeftRadius: config.pageConfig.radiusTop + 'px',
              borderTopRightRadius: config.pageConfig.radiusTop + 'px',
              borderBottomLeftRadius: config.pageConfig.radiusBottom + 'px',
              borderBottomRightRadius: config.pageConfig.radiusBottom + 'px',
            }" v-if="config.pageConfig.imgList[1].imgUrl" :src="config.pageConfig.imgList[1].imgUrl"
              class="banner-img" alt="" />
            <img v-else :style="{
              borderTopLeftRadius: config.pageConfig.radiusTop + 'px',
              borderTopRightRadius: config.pageConfig.radiusTop + 'px',
              borderBottomLeftRadius: config.pageConfig.radiusBottom + 'px',
              borderBottomRightRadius: config.pageConfig.radiusBottom + 'px',
            }" src="../../../../../../assets/app/bar/default_banner.png" class="banner-img" alt="" />
          </div>
          <div class="img-container" :class="config.pageConfig.style == 2 ? 'shadow-style' : ''" :style="{
            borderTopLeftRadius: config.pageConfig.radiusTop + 'px',
            borderTopRightRadius: config.pageConfig.radiusTop + 'px',
            borderBottomLeftRadius: config.pageConfig.radiusBottom + 'px',
            borderBottomRightRadius: config.pageConfig.radiusBottom + 'px',
            borderWidth:
              config.pageConfig.style == 3
                ? config.pageConfig.borderWidth + 'px'
                : '',
            borderColor:
              config.pageConfig.style == 3
                ? config.pageConfig.borderColor
                : '',
          }" v-if="config.pageConfig.imgList.length > 2">
            <img :style="{
              borderTopLeftRadius: config.pageConfig.radiusTop + 'px',
              borderTopRightRadius: config.pageConfig.radiusTop + 'px',
              borderBottomLeftRadius: config.pageConfig.radiusBottom + 'px',
              borderBottomRightRadius: config.pageConfig.radiusBottom + 'px',
            }" v-if="config.pageConfig.imgList[2].imgUrl" :src="config.pageConfig.imgList[2].imgUrl"
              class="banner-img" alt="" />
            <img v-else :style="{
              borderTopLeftRadius: config.pageConfig.radiusTop + 'px',
              borderTopRightRadius: config.pageConfig.radiusTop + 'px',
              borderBottomLeftRadius: config.pageConfig.radiusBottom + 'px',
              borderBottomRightRadius: config.pageConfig.radiusBottom + 'px',
            }" src="../../../../../../assets/app/bar/default_banner.png" class="banner-img" alt="" />
          </div>
        </div>
        <div v-if="config.pageConfig.custom == '3'" class="banner-container style-3">
          <div class="img-container" :class="config.pageConfig.style == 2 ? 'shadow-style' : ''" :style="{
            borderTopLeftRadius: config.pageConfig.radiusTop + 'px',
            borderTopRightRadius: config.pageConfig.radiusTop + 'px',
            borderBottomLeftRadius: config.pageConfig.radiusBottom + 'px',
            borderBottomRightRadius: config.pageConfig.radiusBottom + 'px',
            borderWidth:
              config.pageConfig.style == 3
                ? config.pageConfig.borderWidth + 'px'
                : '',
            borderColor:
              config.pageConfig.style == 3
                ? config.pageConfig.borderColor
                : '',
          }" v-if="config.pageConfig.imgList.length > 0">
            <img :style="{
              borderTopLeftRadius: config.pageConfig.radiusTop + 'px',
              borderTopRightRadius: config.pageConfig.radiusTop + 'px',
              borderBottomLeftRadius: config.pageConfig.radiusBottom + 'px',
              borderBottomRightRadius: config.pageConfig.radiusBottom + 'px',
            }" v-if="config.pageConfig.imgList[0].imgUrl" :src="config.pageConfig.imgList[0].imgUrl"
              class="banner-img" alt="" />
            <img v-else :style="{
              borderTopLeftRadius: config.pageConfig.radiusTop + 'px',
              borderTopRightRadius: config.pageConfig.radiusTop + 'px',
              borderBottomLeftRadius: config.pageConfig.radiusBottom + 'px',
              borderBottomRightRadius: config.pageConfig.radiusBottom + 'px',
            }" src="../../../../../../assets/app/bar/default_banner.png" class="banner-img" alt="" />
          </div>
          <div class="img-container" :class="config.pageConfig.style == 2 ? 'shadow-style' : ''" :style="{
            marginLeft: config.pageConfig.marginImg + 'px',
            marginRight: config.pageConfig.marginImg + 'px',
            borderTopLeftRadius: config.pageConfig.radiusTop + 'px',
            borderTopRightRadius: config.pageConfig.radiusTop + 'px',
            borderBottomLeftRadius: config.pageConfig.radiusBottom + 'px',
            borderBottomRightRadius: config.pageConfig.radiusBottom + 'px',
            borderWidth:
              config.pageConfig.style == 3
                ? config.pageConfig.borderWidth + 'px'
                : '',
            borderColor:
              config.pageConfig.style == 3
                ? config.pageConfig.borderColor
                : '',
          }" v-if="config.pageConfig.imgList.length > 1">
            <img :style="{
              borderTopLeftRadius: config.pageConfig.radiusTop + 'px',
              borderTopRightRadius: config.pageConfig.radiusTop + 'px',
              borderBottomLeftRadius: config.pageConfig.radiusBottom + 'px',
              borderBottomRightRadius: config.pageConfig.radiusBottom + 'px',
            }" v-if="config.pageConfig.imgList[1].imgUrl" :src="config.pageConfig.imgList[1].imgUrl"
              class="banner-img" alt="" />
            <img :style="{
              borderTopLeftRadius: config.pageConfig.radiusTop + 'px',
              borderTopRightRadius: config.pageConfig.radiusTop + 'px',
              borderBottomLeftRadius: config.pageConfig.radiusBottom + 'px',
              borderBottomRightRadius: config.pageConfig.radiusBottom + 'px',
            }" v-else src="../../../../../../assets/app/bar/default_banner.png" class="banner-img" alt="" />
          </div>
          <div class="img-container" :class="config.pageConfig.style == 2 ? 'shadow-style' : ''" :style="{
            borderTopLeftRadius: config.pageConfig.radiusTop + 'px',
            borderTopRightRadius: config.pageConfig.radiusTop + 'px',
            borderBottomLeftRadius: config.pageConfig.radiusBottom + 'px',
            borderBottomRightRadius: config.pageConfig.radiusBottom + 'px',
            borderWidth:
              config.pageConfig.style == 3
                ? config.pageConfig.borderWidth + 'px'
                : '',
            borderColor:
              config.pageConfig.style == 3
                ? config.pageConfig.borderColor
                : '',
          }" v-if="config.pageConfig.imgList.length > 2">
            <img :style="{
              borderTopLeftRadius: config.pageConfig.radiusTop + 'px',
              borderTopRightRadius: config.pageConfig.radiusTop + 'px',
              borderBottomLeftRadius: config.pageConfig.radiusBottom + 'px',
              borderBottomRightRadius: config.pageConfig.radiusBottom + 'px',
            }" v-if="config.pageConfig.imgList[2].imgUrl" :src="config.pageConfig.imgList[2].imgUrl"
              class="banner-img" alt="" />
            <img v-else :style="{
              borderTopLeftRadius: config.pageConfig.radiusTop + 'px',
              borderTopRightRadius: config.pageConfig.radiusTop + 'px',
              borderBottomLeftRadius: config.pageConfig.radiusBottom + 'px',
              borderBottomRightRadius: config.pageConfig.radiusBottom + 'px',
            }" src="../../../../../../assets/app/bar/default_banner.png" class="banner-img" alt="" />
          </div>
        </div>
      </div>
    </div>
  </div>
</template>
<script lang="ts">
export default {
  name: "ImgCarousel",
};
</script>
<script lang="ts" setup>
import { reactive, onMounted } from "vue";
// import { Swipe as VanSwipe, SwipeItem as VanSwipeItem } from "vant";
const config = defineProps({
  pageConfig: {
    type: Object,
    default: {
      custom: "1",
      style: "1",
      dotshow: true,
      dotStyle: "1",
      position: "1",
      color: "transparent",
      borderColor: "transparent",
      borderWidth: 1,
      marginTop: 0,
      marginBottom: 0,
      marginImg: 5,
      margin: 0,
      radiusTop: 0,
      radiusBottom: 0,
      imgList: [
        {
          imgUrl: "",
          name: "",
          url: "",
        },
        {
          imgUrl: "",
          name: "",
          url: "",
        },
      ],
    },
  },
});
console.log(config.pageConfig);
let emits = defineEmits<{ (e: "close", flag: boolean): void }>();
// const config = reactive({
//   custom: "1",
//   style: "1",
//   dotshow: true,
//   dotStyle: "1",
//   color: "",
//   marginTop: 0,
//   marginBottom: 0,
//   margin: 0,
//   radiusTop: 0,
//   radiusBottom: 0,
//   imgList: [
//     {
//       imgUrl: "",
//       name: "",
//       url: "",
//     },
//     {
//       imgUrl: "",
//       name: "",
//       url: "",
//     },
//   ],
// });
//
const getFlex = (style: string) => {
  if (style == "1") {
    return "text-align:left;";
  } else if (style == "2") {
    return "text-align:center;";
  } else if (style == "3") {
    return "text-align:right;";
  }
};
const getName = (style: string) => {
  if (style == "1") {
    return "round";
  } else if (style == "2") {
    return "arc";
  } else if (style == "3") {
    return "square";
  }
};
</script>
<style lang="scss" scoped>
.banner {
  width: 100%;
  // height: unset;
  // height: 210px;
  position: relative;
  overflow: hidden;
}

.img {
  width: 100%;
  display: block;
  background-size: cover;
  background-repeat: no-repeat;
  background-position: 50%;
  overflow: hidden;
  position: relative;

  .banner-img {
    width: 100%;
    display: block;
  }

  .dots {
    position: absolute;
    bottom: 16px;
    left: 0;
    width: 100%;
    height: 14px;
    padding: 0 10px;
    box-sizing: border-box;

    .dot-page {
      display: inline-block;
      text-align: center;
      border-radius: 10px;
      background: rgba(0, 0, 0, 0.5);
      color: #fff;
      padding: 2px 6px;
      letter-spacing: 3px;
      font-size: 12px;
    }

    &.arc {
      .dot {
        display: inline-block;
        height: 6px;
        width: 6px;
        border-radius: 10px;
        background: #ccc;
        margin: 0 4px;

        &.active {
          height: 6px;
          width: 14px;
          border-radius: 6px;
          background: #fff;
        }
      }
    }

    &.round {
      .dot {
        display: inline-block;
        height: 6px;
        width: 6px;
        border-radius: 10px;
        background: #ccc;
        margin: 0 4px;

        &.active {
          background: #fff;
        }
      }
    }

    &.square {
      .dot {
        display: inline-block;
        height: 3px;
        width: 16px;
        border-radius: 0;
        margin: 0 4px;
        background: #ccc;

        &.active {
          background: #fff;
        }
      }
    }
  }
}

.shadow-style {
  border: none;
  box-shadow: 0 0 10px rgba(129, 131, 136, 0.7);
  -webkit-box-shadow: 0 0 10px rgba(129, 131, 136, 0.7);
  -moz-box-shadow: 0 0 10px rgba(129, 131, 136, 0.7);
}

.banner-container {
  height: 100%;
  width: 100%;
  // display: flex;
  box-sizing: border-box;
  // align-items: center;
}

.img-container {
  overflow: hidden;
}

.style-2 {
  overflow: hidden;
  display: flex;

  .img-container {
    box-sizing: border-box;
    align-items: center;
    overflow: hidden;
  }

  .img-container:nth-child(3n + 1) {
    height: 80%;
    vertical-align: middle;
    width: 8%;
    background-position: 100% 0 !important;
    border-top-left-radius: 0 !important;
    border-bottom-left-radius: 0 !important;
    direction: rtl;
    unicode-bidi: bidi-override;

    img {
      transform: scaleY(0.8);
      width: 1050%;
    }
  }

  .img-container:nth-child(3n + 2) {
    height: 100%;
    width: 84%;
    display: block;
    background-size: cover;
    background-repeat: no-repeat;
    background-position: 50%;
  }

  .img-container:nth-child(3n) {
    height: 80%;
    vertical-align: middle;
    width: 8%;
    background-position: 0 0 !important;
    border-top-right-radius: 0 !important;
    border-bottom-right-radius: 0 !important;

    img {
      transform: scaleY(0.8);
      width: 1050%;
    }
  }
}

.style-3 {
  overflow: hidden;
  display: flex;

  .img-container {
    box-sizing: border-box;
    align-items: center;
    overflow: hidden;
  }

  .img-container:first-child {
    height: 80%;
    vertical-align: middle;
    width: 8%;
    background-position: 100% 0 !important;
    border-top-left-radius: 0 !important;
    border-bottom-left-radius: 0 !important;
    direction: rtl;
    unicode-bidi: bidi-override;

    img {
      width: 1050%;
    }
  }

  .img-container:nth-child(2) {
    height: 100%;
    width: 84%;
    display: block;
    background-size: cover;
    background-repeat: no-repeat;
    background-position: 50%;
  }

  .img-container:nth-child(3) {
    height: 100%;
    vertical-align: middle;
    width: 8%;
    background-position: 0 0 !important;
    border-top-right-radius: 0 !important;
    border-bottom-right-radius: 0 !important;

    img {
      width: 1050%;
    }
  }
}

.img-container {
  border: 1px solid transparent;
}
</style>
